
// 1. map
const map = (array, fn) => {
   let res = [];
   for (let value of array) {
     res.push(fn(value));
   }

   return res;
};

// 测试
let arr = [1, 3, 5, 7];
arr = map(arr, v => v * v);
console.log(arr);

// 2.every
const every = (array, fn) => {
  let res = true;
  for (let value of array) {
    res = fn(value);

    if (!res) break;
  }

  return res;
}

// 测试
let arr2 = [10, 13, 15];
let bool = every(arr2, v => v > 10);
console.log(bool); // false

// 3.some
const some = (array, fn) => {
  let res = false;

  for (let value of array) {
    res = fn(value);

    if (res) break;
  }

  return res;
}

// 测试
let arr3 = [2, 5, 7, 9];
let res3 = some(arr3, v => v % 2 === 0);
console.log(res3); // true
